<template>
    <el-dialog title="标签" id="productTag" :close-on-click-modal="false" :visible.sync="show" class="dialog_index"
   :before-close="cancle">
      <el-form >
        <el-form-item label="标签类型：" >
          <el-select  v-model="tag_type" placeholder="标签类型" clearable  @keyup.enter.native="getTableList">
            <el-option v-for="item in tagList" :key="item.id" :value="item.value" :label="item.label"></el-option>
          </el-select>
         </el-form-item>
      </el-form>
     <span slot="footer" class="dialog-footer">
      <el-button type="search" @click="submitForm">保存</el-button>
      <el-button @click="cancle">取消</el-button>
    </span>
    </el-dialog>
</template>

<script>
import { productBasicTag } from '@/api/product/productBasic.js'
export default {
  data () {
    return {
      tag_type: '',
      tagList: [
        {value: 1, label: 'NEW'},
        {value: 2, label: 'HOT'},
        {value: 3, label: 'Nothing'},
        {value: 4, label: '推荐'},
      ],
    }
  },
  props: {
    show: Boolean,
    closeDialog:Function,
    idList: Array
  },
  methods: {
    submitForm () {
      let status = this.validateForm()
      if(status){
        this.updateTag()
      }
    },
    validateForm () {
      let status = true;
      if(!this.tag_type){
        this.$message.error('字段标签类型为必填项！');
        status = false
      }
      return status
    },
    updateTag () {
      let params  ={
        product_id:JSON.stringify(this.idList),
        tag_type: this.tag_type
      }
      productBasicTag(params).then(res=>{
        if(res.state == 1){
          this.$message.success('保存成功')
          this.cancle()
        }
      })
    },
    cancle(){
      this.$emit('closeDialog')
      this.tag_type = ''
    },
  }

}
</script>

<style>
#productTag.el-dialog__wrapper > .el-dialog .el-dialog__body{
  padding: 24px 48px ;
}

</style>